<?php

class Controller {
	
	private $sysConfig = null;
	protected $smarty = null;
	
	function __construct(){
		
		$arrSysConfig = null;
		$configFile = APP_PATH.'/Config/SysConfig.php';
		if (file_exists($configFile)){
			$arrSysConfig = require_once APP_PATH.'/Config/SysConfig.php';
		}
		$this->setSysConfig($arrSysConfig);
		
		if (!defined('UPLOAD_PATH')) define('UPLOAD_PATH', $arrSysConfig['UPLOAD_PATH']);
		
		include_once(LS_PATH."/Smarty/Smarty.class.php"); //包含smarty类文件
		$smarty = new Smarty(); //建立smarty实例对象$smarty
		$smarty->config_dir=LS_PATH."/Smarty/Config_File.class.php";  // 目录变量
		$smarty->caching=false; //是否使用缓存，项目在调试期间，不建议启用缓存
		$smarty->template_dir = $arrSysConfig['TEMPLATE']['TEMPLATE_DIR']; //设置模板目录
		$smarty->compile_dir = $arrSysConfig['TEMPLATE']['COMPILE_DIR']; //设置编译目录
		$smarty->cache_dir = "./smarty_cache"; //缓存文件夹
		
		//设置资源路径
		$smarty->assign('CSS',$this->arrSysConfig['RESOURCE_PATH']['CSS_PATH']);
		$smarty->assign('IMAGE',$this->arrSysConfig['RESOURCE_PATH']['IMAGE_PATH']);
		$smarty->assign('JS',$this->arrSysConfig['RESOURCE_PATH']['JS_PATH']);
		$smarty->assign('Editor',$this->arrSysConfig['RESOURCE_PATH']['EDITOR_PATH']);
        $smarty->assign('CURRENTCLASS',strtolower(str_replace('Action','',$this->strClassName)));
        $smarty->assign('CURRENTACTION',strtolower($this->strActionName));
        
		$this->smarty = $smarty;
		
		$app_name = strtolower(APP_NAME);
		$theme_name = strtolower(THEME_NAME);
	}
	
	/**
	 * 设置系统配置
	 * @param array $arrSysConfig	系统配置
	 */
	private function setSysConfig($arrSysConfig)
	{
		$this->arrSysConfig = $arrSysConfig;
	}
	
	protected function display($template,array $assigns=null)
    {
    	/*if ($strMasterName=='Common/Master.html'){
    		$this->smarty->assign('contenttpl',$template);
    	} else {
    		$strMasterName = $template;
    	}*/
    	if(isset($assigns))
		{			
			foreach($assigns as $smartName=>$assignValue)
			{
				$this->smarty->assign($smartName,$assignValue);
			}
		}
    	$this->smarty->display($template);
    }
    
 	protected function assign($tpl_var, $value = null)
    {
    	$this->smarty->assign($tpl_var, $value); 
    }
    
	public static function hello() {
		echo 123;
	}
	
	
}